package ch00.ch01;

import java.lang.reflect.Field;

/**
 * @Author lzp
 * @Date 2024-04-02
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Student student =new Student();
        Class<? extends Student> aClass = student.getClass();

        //获取字段
        Field field = aClass.getDeclaredField("age");
        boolean bl2 = field.isAnnotationPresent(CheckAge.class) ;
        //System.out.println(bl2);
        if (bl2 == true){
            CheckAge annotation = field.getAnnotation(CheckAge.class);
            //System.out.println(annotation.age());
            Student stu =new Student("张三",20);
            int age = stu.getAge();

            if (age < annotation.age()){
                throw new RuntimeException("不能低于" + age +"岁");
            }
            System.out.println("名字" + stu.getName() + "年龄"+ age);
        }


    }
}
